<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>信审驳回意见</title>
<jsp:include page="../../import.jsp" flush="true" />
<style>
.inputyj{
-moz-border-radius:5px;
          -webkit-border-radius:5px;
          -ms-border-radius:5px;
          -khtml-border-radius:5px;
           border-radius:5px;
}
</style>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <table class="layout2col1">
        <tbody>
            <tr>
                <td width="50%" valign="top">
                    <div class="sqPanel">
                        <div class="sqPanel_head">
                            <span><i class="sqIco sqIco_3"></i>信审意见</span>
                        </div>
                        <div class="sqPanel_body" style="min-height: 500px;">
                            <div class="btnsBox">
                                <!-- <span class="sq-button sq-button-hasicon" id="addPlat_button"><i class="sqBtnIco_3"></i>新增平台</span> -->
                    			<div>
                    			<span>事业部</span>
                                <select class="inputyj" name="buOrgCd" id="buOrgCd" data-value="" validate="{select: true}">
			            		<option value="0000" checked>全公司</option>
			            		<c:forEach items="${buOrgCdList }" var="boc">
                        			<option value="${boc.key }">${boc.value }</option>
                        		</c:forEach>
			         			</select>
                                <span>原因分类</span>
                                <select class="inputyj" name="type" id="type" data-value="" validate="{select: true}">
			            		<c:forEach items="${rejRsnList }" var="rsn">
                        			<option value="${rsn.key }">${rsn.value }</option>
                        		</c:forEach>
			         			</select>
                                <!-- <span class="sq-button sq-button-hasicon" id="remove_button"><i class="sqBtnIco_7"></i>删除</span> -->
                                <span class="sq-button sq-button-hasicon" id="reloadTree_btn"><i class="sqBtnIco_28"></i>更新</span>
                                <span onclick="refreshSystem();" class="sq-button sq-button-hasicon"><i class="sqBtnIco_1"></i>数据同步</span>
                                <!-- <span class="sq-button sq-button-hasicon onlyicon" title="上移"><i class="sqBtnIco_9"></i></span>
                                <span class="sq-button sq-button-hasicon onlyicon" title="下移"><i class="sqBtnIco_8"></i></span>
                                <span class="sq-button sq-button-hasicon onlyicon" id="demotion_btn" title="降级"><i class="sqBtnIco_17"></i></span>
                                <span class="sq-button sq-button-hasicon onlyicon" id="upgrade_btn" title="升级"><i class="sqBtnIco_18"></i></span> -->
                            </div>
                            <br/>
                            <ul id="tree1" style="width:400px">
                            </ul>
                        </div>
                    </div>
                   </div>
                </td>
                <td width="50%" valign="top">
                    <div class="sqPanel">
                        <div class="sqPanel_head">
                            <span><i class="sqIco sqIco_4"></i>意见详细</span>
                        </div>
                        <div class="sqPanel_body">
                            <div class="btnsBox" id="btnIsShow">
                                <span class="sq-button sq-button-hasicon" id="change_btn"><i class="sqBtnIco_4"></i>修改</span>
                                <span class="sq-button sq-button-hasicon Hide" id="saveChange_btn"><i class="sqBtnIco_10"></i>保存</span>
                                <span class="sq-button sq-button-hasicon Hide" id="saveNew_btn"><i class="sqBtnIco_3"></i>保存</span>
                            </div>
                            <form id="sysOrg_form" class="Hide">
                            <input name="pid" id="pid" type="text" style="display: none;" value=""/>
                            <input name="oid" id="oid" type="text" style="display: none;" value=""/>
                                <div class="fieldset1 tabel_col tabel_col_1 clearFix">
                                    <div class="fieldBox col_1_100">
                                        <div class="label">原因分类</div>
                                        <div class="field">
                                            <select name="rsnTypCd" id="rsnTypCd" data-value="" validate="{select: true}">
			            						<c:forEach items="${rejRsnList }" var="rsn">
                        							<option value="${rsn.key }">${rsn.value }</option>
                        						</c:forEach>
			         						</select>
                                        </div>
                                    </div>
                                    <div class="fieldBox col_1_100">
                                        <div class="label">事业部</div>
                                        <div class="field">
                                        	<select name="orgCd" id="orgCd" data-value="" validate="{select: true}">
			            						<option value="0000" checked>全公司</option>
			            						<c:forEach items="${buOrgCdList }" var="boc">
                        							<option value="${boc.key }">${boc.value }</option>
                        						</c:forEach>
			         						</select>
                                        </div>
                                    </div>
                                    <div class="fieldBox col_1_100">
                                        <div class="label">排序序号</div>
                                        <div class="field">
                                        	<input id="sortNo" name="sortNo" class="ui-textbox"/>
                                        </div>
                                    </div>
                                    <div class="fieldBox col_1_100">
                                        <div class="label">原因描述</div>
                                        <div class="field" style="width: 100%;">
                                            <input id="rsnDesc" name="rsnDesc" class="ui-textbox"/>
                                        </div>
                                    </div> 
                                </div>
                                <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                            </form>
                            <form id="sysOrg_form_t">
                                <div class="fieldset1 tabel_col tabel_col_1 clearFix">
                                   <div class="fieldBox col_1_100">
                                        <div class="label">意见ID</div>
                                        <div class="field">
                                        	<span id="id_txt"></span>
                                        </div>
                                    </div>
                                    <div class="fieldBox col_1_100">
                                        <div class="label">原因分类</div>
                                        <div class="field">
                                            <select name="rsnTypCd_txt" id="rsnTypCd_txt"  data-value="" validate="{select: true}">
			            						<c:forEach items="${rejRsnList }" var="rsn">
                        							<option value="${rsn.key }">${rsn.value }</option>
                        						</c:forEach>
			         						</select>
                                        </div>
                                    </div>
                                    <div class="fieldBox col_1_100">
                                        <div class="label">事业部</div>
                                        <div class="field">
                                        	<select name="orgCd_txt" id="orgCd_txt"  data-value="" validate="{select: true}">
			            						<option value="0000" checked>全公司</option>
			            						<c:forEach items="${buOrgCdList }" var="boc">
                        							<option value="${boc.key }">${boc.value }</option>
                        						</c:forEach>
			         						</select>
                                        </div>
                                    </div>
                                    <div class="fieldBox col_1_100">
                                        <div class="label">排序序号</div>
                                        <div class="field">
                                        	<span id="sortNo_txt"></span>
                                        </div>
                                    </div>
                                    <div class="fieldBox col_1_100">
                                        <div class="label">原因描述</div>
                                        <div class="field" style="width: 100%;">
                                            <span id="rsnDesc_txt"></span>
                                        </div>
                                    </div> 
                                </div>
                            </form>
                        </div>
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
</div>



<script type="text/javascript">

	var tree,
	    treeMenu,
	    treeMenu2,
	    actionNode,  //鼠标右击时的节点
	    Editable=true;
	$(function () {
		$("#sysOrg_form").ligerForm({
			validate: true
	    });
		liger.get("rsnTypCd").setDisabled(true);
		liger.get("orgCd").setDisabled(true);
		$("#sysOrg_form_t").ligerForm({
			validate: true
	    });
		liger.get("rsnTypCd_txt").setDisabled(true);
		liger.get("orgCd_txt").setDisabled(true);
		
    treeMenu = $.ligerMenu({
        top: 100,
        left: 100,
        width: 120,
        items:[
			{ text: '添加同级参数', click: addPeerNode, icon: 'addSameLevel' },
			{ text: '删除参数', click: removeNode, icon: 'removeSameLevel' }
           /*  { text: '添加子级参数', click: addChildNode, icon: 'addSubLevel' } */
        ]
    });
    treeMenu2 = $.ligerMenu({
        top: 100,
        left: 100,
        width: 120,
        items:[
            { text: '添加同级参数', click: addPeerNode, icon: 'addSameLevel' },
            { text: '添加子级参数', click: addChildNode, icon: 'addSubLevel' },
            { text: '删除参数', click: removeNode, icon: 'removeSameLevel' }
           
        ]
    });
    
    onSelectChange();
    $("#type").on("change",onSelectChange);
    $("#buOrgCd").on("change",onSelectChange);
    
    function onSelectChange(){
    	rsnTypCd = $("#type").val();
    	buOrgCd = $("#buOrgCd").val();
    	tree = $("#tree1").ligerTree({
        	url: '<%=path%>/flow/sysflowrejrsn/initTreeList.do?rsnTypCd='+rsnTypCd+'&buOrgCd='+buOrgCd+'&id='+0,
            ajaxType: 'get',
            checkbox: false,
            parentIcon: "SqFolder",
            childIcon: "SqLeaf",
            needCancel:false,
            isExpand: false,
            isLeaf: function (data) {
             	if (!data) return false;
                if(data.hasChildren){return false} else {return true};
             },
             delay: function(e)
             {
                 var data = e.data;
                 if (data.hasChildren)
                 {
                     return { url: '<%=path%>/flow/sysflowrejrsn/initTreeList.do?rsnTypCd='+rsnTypCd+'&buOrgCd='+buOrgCd+'&id='+data.id	}
                 }
                 return false;
             },
            onContextmenu: function (node, e) {
                actionNode=node;
                var parentNode = tree.getParent(node);
                if (node.data.rsnLvl!='3') {
                    treeMenu.hide();
                    treeMenu2.show({ top: e.pageY, left: e.pageX });
                }else{  //没有父节点，那就是根节点
                    treeMenu2.hide();
                    treeMenu.show({ top: e.pageY, left: e.pageX }); 
                	/* treeMenu.hide();
                    treeMenu2.show({ top: e.pageY, left: e.pageX }); */
                };
                return false;
            },
            onSelect: onSelectTree,
           onCancelselect: function (data,target) {
            	 $("#sysOrg_form").addClass('Hide');
                 $("#sysOrg_form_t").removeClass('Hide');
            }, 
            onSuccess: function (data) {
            	if(data==""){
            		$("#sysOrg_form").addClass('Hide');
                    $("#sysOrg_form_t").addClass('Hide');
                    $("#btnIsShow").hide();
            	}else{
            		$("#btnIsShow").show();
            	}
                // 初始化的时候默认选中某个树节点
               /*  var selectNode_parm = function (treeData){
                    return treeData.text == '节点1';
                };
                tree.selectNode(selectNode_parm); */
                tree.selectNode(data[0]);
                //tree.selectNode(data[0].id);
            }
        });
    }
    
    $("#change_btn").click(function(event) {
    	 if(Editable==false){
    		top.$.ligerDialog.SQalert({content: LogUtils.LOG_SYS_ORG_INSIDE_FORBID_HANDLE,SQ_type: "warning"});
    		return;
    	};
    	var selectedTree_node=tree.getSelected();
        if (!selectedTree_node) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_SYS_ORG_SELECT_BEFORE,SQ_type: "warning"});
            return;
        }
    	$("#saveChange_btn").removeClass("Hide");
    	$("#change_btn").addClass("Hide");
        changeForm();
        setLigerForm();
        var form = new liger.get("sysOrg_form");
   	 	form.setData({  //重置select等特殊表单
	            "orgCd": " ", 
	        });
        $.ajax({
  			type: 'get',
  			dataType:'json',
  			data:{id:idEdit},
  			url: '<%=path%>/flow/sysflowrejrsn/getById.do',
  			success:function(msg){
  				 if(msg.success == 1){
  					setValueToInput(msg.data)
  				 }else{
  				 }
  			}
  		});
        
    });
    
    function removeNode(){
    	rsnTypCd = $("#type").val();
    	orgCd = $("#buOrgCd").val();
    	
    	/* if(Editable==false){
    		top.$.ligerDialog.SQalert({content: LogUtils.LOG_SYS_ORG_INSIDE_FORBID_HANDLE,SQ_type: "warning"});
    		return;
    	};
    	var selectedTree_node=tree.getSelected();
        if (!selectedTree_node) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_SYS_ORG_SELECT_BEFORE,SQ_type: "warning"});
            return;
        } */
        var showName = actionNode.data.text;
        $.ligerDialog.confirm('连同  "'+showName+'" 下的子参数也将被删除，是否确认删除？', function (flag) {
        	if(flag == false)return;
			$.ajax({
	  			type: 'post',
	  			dataType:'json',
	  			data:{
	  				id:actionNode.data.id,
	  				rsnTypCd:rsnTypCd,
	  				orgCd:orgCd
	  			},
	  			url: '<%=path%>/flow/sysflowrejrsn/removeById.do',
	  			success:function(msg){
	  				 if(msg.success == 1){
	  					top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
	  					tree.reload();
	  					$("#resetBtn").click();
	  					 
	  				 }else{
	  					top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	  				 }
	  			}
	  		});
		});
    }
    
    $("#remove_button").click(function(event) {
    	rsnTypCd = $("#type").val();
    	orgCd = $("#buOrgCd").val();
    	
    	if(Editable==false){
    		top.$.ligerDialog.SQalert({content: LogUtils.LOG_SYS_ORG_INSIDE_FORBID_HANDLE,SQ_type: "warning"});
    		return;
    	};
    	var selectedTree_node=tree.getSelected();
        if (!selectedTree_node) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_SYS_ORG_SELECT_BEFORE,SQ_type: "warning"});
            return;
        }
        var showName = selectedTree_node.data.text;
        $.ligerDialog.confirm('连同  "'+showName+'" 下的子参数也将被删除，是否确认删除？', function (flag) {
        	if(flag == false)return;
			$.ajax({
	  			type: 'post',
	  			dataType:'json',
	  			data:{
	  				id:selectedTree_node.data.id,
	  				rsnTypCd:rsnTypCd,
	  				orgCd:orgCd
	  			},
	  			url: '<%=path%>/flow/sysflowrejrsn/removeById.do',
	  			success:function(msg){
	  				 if(msg.success == 1){
	  					top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
	  					tree.reload();
	  					$("#resetBtn").click();
	  					 
	  				 }else{
	  					top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	  				 }
	  			}
	  		});
		});
        
        
        
        
    });
    $("#addPlat_button").click(function(event) {
    	 $("#resetBtn").click();
    	swithBtn()
        changeForm();
    	 setLigerForm();
    	 var form = new liger.get("sysOrg_form");
    	 form.setData({  //重置select等特殊表单
	            "orgTypCd": " ",
	        });
    });
    
    $("#reloadTree_btn").click(function(event) {
        tree.reload();
    });
   
    $("#saveNew_btn").click(function(event) {
    	
    	var form = new liger.get("sysOrg_form");
        if (!form.valid()) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
            return false; //验证不通过，不执行以下代码
        }
  	    var data = form.getData();
  	   // alert(JSON.stringify(data));
  	   
  	    $.ajax({
  			type: 'post',
  			dataType:'json',
  			data:data,
  			url: '<%=path%>/flow/sysflowrejrsn/add.do',
  			success:function(msg){
				$(this).addClass("Hide");
		    	$(this).siblings(".sq-button").removeClass("Hide");
  				 if(msg.success == 1){
  					top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
  					 var node = msg.data;
  					 tree.reload(function(){
  						setExpand2Parents (node, "tree1");
  		                tree.selectNode(node);
  					 });
  				 }else{
  					top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
  				 }
  			}
  		});
    });
    var idEdit;
    function changeForm () {
        $("#sysOrg_form_t").addClass('Hide');
        $("#sysOrg_form").removeClass('Hide');
        setForm();
       
    }
    function detailForm () {
        $("#sysOrg_form").addClass('Hide');
        $("#sysOrg_form_t").removeClass('Hide');
    }
    function onSelectTree (node) {
    	$("#saveNew_btn").addClass("Hide");
    	$("#saveChange_btn").addClass("Hide");
    	$("#change_btn").removeClass("Hide");
        //console.log(node.data);
        //alert(JSON.stringify(node));
        detailForm ()
         $.ajax({
  			type: 'get',
  			dataType:'json',
  			data:{id:node.data.id},
  			url: '<%=path%>/flow/sysflowrejrsn/getById.do',
  			success:function(msg){
  				 if(msg.success == 1){
  					setValueToText(msg.data);
  					idEdit =msg.data.id;
  					//isEditable(msg.data.isSysDef);
  					 
  				 }else{
  					 
  				 }
  			}
  		});
    }
    /*
    	是否系统内置参数获取
    */
    function isEditable(isSysDef){
    	if(isSysDef==0){
    		Editable=true;
    	}else{
    		Editable=false;
    	}
    }
    function treeMenu_handler_1 (item, i) {
        //alert(item.text+ "\n" +JSON.stringify(item)+ "\n" +actionNode.data.text+ "\n" +JSON.stringify(actionNode));
        console.log(item, i, actionNode);
    }
    //添加子级架构
    function addChildNode (){
    	 $("#resetBtn").click();
    	 swithBtn();
    	var id = actionNode.data.id;
    	var text=actionNode.data.text;
    	var orgCd = $("#buOrgCd").val();
    	var type = $("#type").val();
    	changeForm();
    	setLigerForm();
    	var form = new liger.get("sysOrg_form");
   	 	form.setData({  //重置select等特殊表单
	            "orgCd": orgCd,
	            "rsnTypCd": type,
	        });
    	//$("#parOrgDispNm").val(text);
    	$("#pid").val(id);
    }
  //添加同级架构
    function addPeerNode (){
    	 $("#resetBtn").click();
    	 swithBtn();
    	var pid = actionNode.data.pid;
    	var orgCd = $("#buOrgCd").val();
    	var type = $("#type").val();
    	changeForm();
    	setLigerForm();
    	var form = new liger.get("sysOrg_form");
   	 	form.setData({  //重置select等特殊表单
	            "orgCd": orgCd,
	            "rsnTypCd": type,
	        });
    	$("#pid").val(pid);
    	 <%--  $.ajax({
    			type: 'get',
    			dataType:'json',
    			data:{id:pid},
    			url: '<%=path%>/system/sysOrg/getById.do',
    			success:function(msg){
    				 if(msg.success == 1){
    					 $("#parOrgDispNm").val(msg.data.orgNm);
    				 }
    			}
    		}); --%>
    	
    }
  	//修改中的保存按钮
     $("#saveChange_btn").click(function(){
    	 if(Editable==false){
     		top.$.ligerDialog.SQalert({content: LogUtils.LOG_SYS_ORG_INSIDE_FORBID_HANDLE,SQ_type: "warning"});
     		return;
     	};
    	var form = new liger.get("sysOrg_form");
    	if (!form.valid()) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
            return false; //验证不通过，不执行以下代码
        }
  	    var data = form.getData();
  	    
  	   // alert(JSON.stringify(data));
  	   data["id"] = $("#oid").val();
  	    $.ajax({
  			type: 'post',
  			dataType:'json',
  			data:data,
  			url: '<%=path%>/flow/sysflowrejrsn/modify.do',
				success : function(msg) {
					if (msg.success == 1) {
						$("#saveChange_btn").addClass("Hide");
						$("#change_btn").removeClass("Hide");
						top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
						var node = $("#oid").val()
						tree.reload(function() {
							setExpand2Parents(node, "tree1");
							tree.selectNode(node);
						});

					} else {
						top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					}
				}
			});
		});

		function setForm() {
			$("#sysOrg_form").ligerForm({
				validate : true
			});
		}
		function swithBtn() {
			$("#saveNew_btn").removeClass("Hide");
			$("#saveNew_btn").siblings(".sq-button").addClass("Hide");
		}
		//赋值方法到详细
		function setValueToText(data) {
			var form = new liger.get("sysOrg_form_t");
			form.setData({
				orgCd_txt : data.orgCd,
				rsnTypCd_txt : data.rsnTypCd
			});
			$("#id_txt").text(isNulltoNBSP(data.id));
			$("#rsnTypCd_txt").val(isNulltoNBSP(data.rsnTypCd));
			$("#orgCd_txt").val(isNulltoNBSP(data.orgCd));
			$("#sortNo_txt").text(isNulltoNBSP(data.sortNo));
			$("#rsnDesc_txt").text(isNulltoNBSP(data.rsnDesc));
		}
		//赋值方法到输入框
		function setValueToInput(data) {
			$("#oid").val(data.id);
			var form = new liger.get("sysOrg_form");
			form.setData({
				orgCd : data.orgCd,
				rsnTypCd : data.rsnTypCd
			});
			$("#rsnTypCd").val(isNulltoNBSP(data.rsnTypCd));
			$("#orgCd").val(isNulltoNBSP(data.orgCd));
			$("#sortNo").val(isNulltoNBSP(data.sortNo));
			$("#rsnDesc").val(isNulltoNBSP(data.rsnDesc));

		}
		function isNulltoNBSP(a) {
			if (a == null || a == undefined) {
				return ""
			} else {
				return a;
			}
		}
		function setLigerForm() {
			var ligerForm = liger.get("sysOrg_form")
			if (ligerForm) {
				return ligerForm;
			}
			$("#sysOrg_form").ligerForm({
				validate : true
			});
		}
		;
		function setExpand2Parents(nodeid, treeid) {
			var tree = liger.get("tree1");
			var parent = tree.getParent(tree.getDataByID(nodeid));
			if (parent != null) {
				parent.isExpand = true;
				setExpand2Parents(parent.id);
			} else {
				tree.setData(tree.getData());
				console.log(tree.getData());
			}
			;
		}
	});
	
	//刷新系统所有缓存
	function refreshSystem(){
		top.$.ligerDialog.confirm("是否对所有数据进行数据同步！", function (flag) {
			 if(flag == false)return;
			 var _url = "<%=path%>/flow/sysflowrejrsn/refreshRejRsnSystem.do";
	         var data = {};
	         data["refreshSysCd"] = '11000';
	         AjaxUtils.ajaxPost(_url, data, callback);
		});
	}
	
	//回调
	function callback(msg){
		if(msg.success == 1){
			UIUtils.alertSuccess(msg.info);
		}else{
			UIUtils.alertError(msg.info);
		}
	}
	
</script>
</body>
</html>